﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace StorageInterface.Dialogs
{
    /// <summary>
    /// Interaction logic for NewOutPayment.xaml
    /// </summary>
    public partial class NewOutPayment : Window
    {
        public NewOutPayment(Window win)
        {
            this.Owner = win;
            InitializeComponent();
            numberstorageCB.ItemsSource = Data.GetAllStorages();
            ProductCB.ItemsSource = Data.GetAllProducts();
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            double am = 0;
            double summ = 0;
            if (ProductCB.SelectedItem == null ||
                    NameDocTB.Text == "" ||
                    AmountTB.Text == "" || !double.TryParse(AmountTB.Text,out am) ||
                    SummTB.Text == "" || !double.TryParse(SummTB.Text,out summ) ||
                    //DateTB.SelectedDate == null ||
                    numberstorageCB.SelectedItem == null)
            {
                ErrorHandler.HandleError("Одно из полей не заполнено");
                return;
            }
            try
            {
                Data.NewOutputPayment(ProductCB.SelectedItem as Product, NameDocTB.Text,
                                      am, summ, CommentTB.Text, DateTime.Now, numberstorageCB.SelectedItem as Storage);


            }
            catch (Exception ex) { ErrorHandler.HandleError(ex.Message); }
            Close();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            NewProductDialog npd = new NewProductDialog();
            npd.Owner = this;
            npd.ShowDialog();
            ProductCB.ItemsSource = Data.GetAllProducts();
        }
    }
}
